//copyright (c) 2016 L.W.C<lwc@li.cm>

#include "NCapi.h"

void NC_RegFunction(NC *nc,char *name,int (*fun)(NC *nc)){
	function *f;
	f=(function*)RUB_malloc(nc->rub,sizeof(function));
	f->name=name;
	f->type=FTP_CALL;
	f->u.fun=fun;
	nc->funreg=MRU_Push(nc->funreg,(void*)f);
}

int NC_GetType(NC *nc){
	return nc->stack->v.type;
}

int NC_Pop_int(NC *nc){
value v;
	nc->stack=pop(nc->stack,&v);
	return v.u.i;
}

double NC_Pop_double(NC *nc){
value v;
	nc->stack=pop(nc->stack,&v);
	return v.u.d;
}

char* NC_Pop_pchar(NC *nc){
value v;
	nc->stack=pop(nc->stack,&v);
	return v.u.ptr_c;
}

void NC_Push_int(NC *nc,int i){
value v;
	v.type=VLTP_INT;
	v.u.i=i;
	nc->stack=push(nc->stack,v);
}

void NC_Push_double(NC *nc,double d){
value v;
	v.type=VLTP_DOUBLE;
	v.u.d=d;
	nc->stack=push(nc->stack,v);
}

void NC_Push_pchar(NC *nc,char* c){
value v;
	v.type=VLTP_PCHAR;
	v.u.ptr_c=c;
	nc->stack=push(nc->stack,v);
}